//
//  THotlineViewController.m
//  FengyuanXS
//
//  Created by 王冬 on 2020/7/29.
//  Copyright © 2020 王冬. All rights reserved.
//

#import "THotlineViewController.h"
#import <WebKit/WebKit.h>

@interface THotlineViewController ()<WKUIDelegate>
@property (weak, nonatomic) IBOutlet UIView *backView;
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (nonatomic, strong)WKWebView *webView;
@end

@implementation THotlineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.phoneLabel.text = [NSString stringWithFormat:@"服务热线:%@",[TokenManager getHotTel]];
    self.navigationItem.title = @"热线服务";
    self.webView = [[WKWebView alloc] init];
       NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);";

                WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
                WKUserContentController *wkUController = [[WKUserContentController alloc] init];
                [wkUController addUserScript:wkUScript];

                WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
                wkWebConfig.userContentController = wkUController;

                // 创建设置对象
                WKPreferences *preference = [[WKPreferences alloc]init];
                // 设置字体大小(最小的字体大小)
                preference.minimumFontSize = 12;
                // 设置偏好设置对象
                wkWebConfig.preferences = preference;
                self.webView= [[WKWebView alloc] initWithFrame:self.view.bounds configuration:wkWebConfig];

       
       
         [self.backView addSubview:self.webView];
        self.webView.UIDelegate = self;

         UIEdgeInsets padding = UIEdgeInsetsMake(0, 0, 0, 0);
         [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
             make.edges.equalTo(self.backView).with.insets(padding);
         }];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    [self getdata];
}

-(void)getdata{
    [[ToastManager shardInstance]showSystemProgress:self.view];
    [[ApiManager ShardInstance]getDetailNoticeID:@"27" resultBlock:^(NSDictionary *data, NSError *error) {
           BaseModel *model = [BaseModel mj_objectWithKeyValues:data];
           if (model.code == 1) {
            [[ToastManager shardInstance]hideProgress:self.view];
                [self.webView loadHTMLString:[NSString stringWithFormat:@"%@",data[@"rs"][@"content"]] baseURL:nil];
           }
           
       }];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row ==1) {
        NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",[TokenManager getHotTel]];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }
    
}

// 页面加载完成之后调用
//- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
//
//    //修改字体大小（方法一）
//    NSString *fontSize = [NSString stringWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%d%%'",15];
//    [ webView evaluateJavaScript:fontSize completionHandler:nil];
//
//
//    //修改字体颜色
//    NSString *colorString = [NSString stringWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextFillColor= '#364857'"];
//    [webView evaluateJavaScript:colorString completionHandler:nil];
//}

#pragma mark - Table view data source


/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
